﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication3.Data;

namespace WebApplication3.Controllers
{
    public class HomeController : Controller
	{
		private readonly ApplicationDbContext _applicationDbContext;

		public HomeController(ApplicationDbContext applicationDbContext)
		{
			this._applicationDbContext = applicationDbContext;
		}
        public IActionResult Index()
        {


			var aaa = "abc";
			var md5 = aaa.GetMD5();
			var base64 = md5.GetBase64();

			var sign = aaa.GetMD5().GetBase64();

			var orderEntity = new Data.Entities.OrderEntity {
				 ProductName= "好吃的",
				  ReceiveAddress= "北京市海淀区学清嘉创大厦A座15层",
				   ReceiveMobile= "18888888888",
				    ReceiveName= "顺丰同城",  OpenId="oGXv94ywgATY6zG49iESrzK5cuCE"
			};



			var postData = new Models.SFCreateOrderModel();

			postData.receive = new Models.ReceiveModel()
			{
				user_address = orderEntity.ReceiveAddress,
				user_lng = "116.362175",//orderEntity.ReceiveLongitude,//116.362175,40.022113
				user_lat = "40.022113",//orderEntity.ReceiveLatitude,
				user_name = orderEntity.ReceiveName,
				user_phone = orderEntity.ReceiveMobile

			};

			var customer = _applicationDbContext.Users.SingleOrDefault(s => s.OpenId == orderEntity.OpenId);
			postData.shop = new Models.ShopModel
			{
				shop_address = "广西市场同城揽收",
				shop_name = customer.CNName + "," + customer.ShopNo,
				shop_phone = customer.Mobile,
				shop_lng = orderEntity.CustomerLongitude, //114.071214,22.643877
				shop_lat = orderEntity.CustomerLatitude
			};

			postData.order_detail = new Models.OrderDetailModel
			{
				total_price = 10,
				product_type = 99,
				weight_gram = orderEntity.WeightGram,
				product_num = 1,
				product_type_num = 1,

				ProductDetails = new List<Models.ProductDetailModel> {

					 new Models.ProductDetailModel{
						  product_name=orderEntity.ProductName,
						   product_num=1,
					 }
					 }
			};
			postData.order_time = 1541933980;
			postData.push_time = 1541933980;
			postData.shop_order_id = orderEntity.Id + "";
			var json = postData.SerializeObject();

			var signChar = string.Format("{0}&{1}&{2}", json,
				ConstData.DevId, ConstData.DevKey);


			return View();
        }
    }
}